// mine/pages/terminate/terminate.js
Page({
  /**
   * 页面的初始数据
   */
  data: {
    applicationId: 'SQ' + new Date().getTime().toString().slice(-8),
    applicationTime: '',
    contractNumber: '',
    houseAddress: '',
    expectedTerminationDate: '',
    terminationReason: '',
    reviewStatus: false,
    reviewTime: '',
    completionStatus: false,
    completionTime: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    // 获取合同ID和终止原因
    const contractId = options.contractId || '';
    const reason = options.reason || '个人原因';
    
    // 获取当前时间
    const now = new Date();
    const formatDate = (date) => {
      const year = date.getFullYear();
      const month = (date.getMonth() + 1).toString().padStart(2, '0');
      const day = date.getDate().toString().padStart(2, '0');
      const hours = date.getHours().toString().padStart(2, '0');
      const minutes = date.getMinutes().toString().padStart(2, '0');
      return `${year}-${month}-${day} ${hours}:${minutes}`;
    };
    
    // 计算预计终止日期（当前日期后30天）
    const terminationDate = new Date(now);
    terminationDate.setDate(terminationDate.getDate() + 30);
    
    // 模拟获取合同详情
    this.getContractDetail(contractId, reason, formatDate(now), formatDate(terminationDate));
  },

  /**
   * 获取合同详情
   */
  getContractDetail(contractId, reason, currentTime, terminationDate) {
    // 这里应该是从API获取数据，这里使用模拟数据
    const contractDetail = {
      contractNumber: 'HT202508310001',
      houseAddress: '北京市朝阳区建国路88号智慧社区3号楼1单元101'
    };
    
    this.setData({
      applicationTime: currentTime,
      contractNumber: contractDetail.contractNumber,
      houseAddress: contractDetail.houseAddress,
      expectedTerminationDate: terminationDate,
      terminationReason: reason
    });
  },

  /**
   * 联系客服
   */
  contactCustomerService() {
    wx.makePhoneCall({
      phoneNumber: '400-123-4567',
      success: () => {
        console.log('拨打客服电话成功');
      },
      fail: (err) => {
        console.error('拨打客服电话失败', err);
        wx.showToast({
          title: '拨打电话失败',
          icon: 'none'
        });
      }
    });
  },

  /**
   * 返回合同详情
   */
  backToContractDetail() {
    wx.navigateBack({
      delta: 1
    });
  }
})